import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils

@pytest.mark.skip
@allure.feature('TestCase_02: 从车应用进入车乐汇	')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001052827?url_cache_key=ab49d6eabe9823050826460ca132aea4')
class TestCaseCarpark02:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 车乐汇
        self.carpark_index_page = CommonPage(self.driver).get_carpark_index_page()
        self.carpark_recommend_page = CommonPage(self.driver).get_carpark_recommend_page()
        # APP
        self.app_index_page = CommonPage(self.driver).get_app_index_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('carpark')
        XiaoMaUtils.close_app('app')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=21)
    def test_carpark_02_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的车乐汇图标")
    @pytest.mark.run(order=22)
    def test_carpark_02_2_click_carpark(self):
        try:
            self.launcher_app_list_page.click_appname("车应用")
            self.app_index_page.click_list_app_btn("车乐汇")
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 查看车乐汇是否启动")
    @pytest.mark.run(order=23)
    def test_carpark_02_3_is_display_carpark(self):
        try:
            self.carpark_recommend_page.is_display_carpark_recommend()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_carpark_02.py")
